#ifndef _PAGED_BLOCK_
#define _PAGED_BLOCK_

#include "Node.h"
#include "ForestLoader.h"
#include "FEngineType.h"
#include "QuadTreeNode.h"

// Store the informations about one billbard's four vertices
struct QuadVertex
{
	FE_BILLBOARD* vertex1;
	FE_BILLBOARD* vertex2;
	FE_BILLBOARD* vertex3;
	FE_BILLBOARD* vertex4;
};

namespace FEngine
{
	/**
	 * Represent one page of the Grass Loader.
	 * Each billboard added to the GrassLoader is contained in a page.
	 * Each page mannage its list of objects and send them to the draw call if the page is visible.
	 */
	class PagedBillboardBlock : public QuadTreeNode
	{

		public:

			/**
			 * Constructor.
			 * @param _maxViewDistance View range of the object inside the block.
			 */
			PagedBillboardBlock(float _size, float _maxViewDistance);
			~PagedBillboardBlock();
			
			/**
			 * Add one instance of the object to the scene.
			 * @param _pos Position of the billboard.
			 * @param _sca Scale of the object.
			 * @param _windForce Amplitude of the movement of the billboard.
			 * @param _windOffset Offset of the movement of the wind.
			 */
			void addBillboard(const Vector3& _pos, const Vector3& _sca, float _windForce, float _windOffset);
			
			int	getNumberObject() const;
			int	getNumberVisibleObject() const;

			/**
			 * Add to the given list every visible instance's vertices of the page.
			 * @param _vectorObjectInstance Pointer to the vector storing every matrix.
			 */
			void getVectorObjectInstance(std::vector<FE_BILLBOARD*>* _vectorObjectInstance);


			void _checkVisibleObjects();


		private:
			
			float						mMaximumViewDistance;
			float						mMaximumViewDistanceSquared;
			
			std::vector<QuadVertex*>	mVectorObjectInstance;
			std::vector<QuadVertex*>	mVectorVisibleObjectInstance;

	};

} // namespace FEngine

#endif
